package com.haizhi.crm.biz.task.message.transfer.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.haizhi.crm.biz.model.MessageClientDo;
import com.haizhi.crm.biz.task.message.model.ContextDto;
import com.haizhi.crm.biz.task.message.transfer.TransferService;

import java.util.List;
import java.util.Map;

/**
 * Created by wangshan on 2018/5/23.
 */
public class OuterEventTransfer implements TransferService {

    private static final String COMPANY_KEYS = "company_keys";
    private static final String DETAIL_KEY = "object_key";
    private static final String NAME = "title";
    private static final String TYPE = "sub_type";
    private static final String SPLIT_FLAG = ",";

    @Override
    public ContextDto transfer(Map<String, String> data) {
        ContextDto contextDto = new ContextDto();

        contextDto.setTitle(data.get(NAME));
        List<String> ids = JSON.parseObject(data.get(COMPANY_KEYS), new TypeReference<List<String>>() {
        });
        for (String id : ids) {
            MessageClientDo messageClientDo = new MessageClientDo();
            messageClientDo.setCompanyId(id);
            contextDto.getMessageClientDos().add(messageClientDo);
        }
        contextDto.setEventType(data.get(TYPE));
        contextDto.setDetailKey(data.get(DETAIL_KEY));
        return contextDto;
    }
}
